package cn.zy.framework.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

/**
 * @Author: Administrator
 * @Description:
 * @Date: Created in 17:00 2021/9/11
 * @Modified By:
 * @version: 1.0
 */
public final class StreamUtil {
	private static final Logger LOGGER = LoggerFactory.getLogger(StreamUtil.class);

	/**
	 * 从输入流中获取字符串
	 */
	public static String getString(InputStream input){
		StringBuilder sb = new StringBuilder();
		try {
			BufferedReader br = new BufferedReader(new InputStreamReader(input));
			String line;
			while ((line = br.readLine()) != null){
				sb.append(line);
			}
		} catch (IOException e) {
			LOGGER.error("get string from inputStream failed", e);
			throw new RuntimeException(e);
		}
		return sb.toString();
	}
}
